// pages/admin/config/config.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    var that = this
    // 获取配置信息
    const db = wx.cloud.database()
    const _ = db.command
    let curDate = new Date();
    console.log(curDate)
    db.collection("configs").where({
      _id: "b75ec551-eddd-4830-a830-5af35af0c7cb"
      // _openid: "ohi2m5ITTPWn8NRlT9g5bi3xzJlE"
    }).get({
      success(res) {
        console.log(res.data.length)
        if (res.data.length > 0) {
          wx.setStorageSync("configs", res.data[0])
          var configs = wx.getStorageSync("configs")
          console.log(configs.Notice)

          that.setData({

            Notice: configs.Notice,
            Price: configs.Price,
            visitTotal_num: configs.visitTotal_num,
            forksCount_num: configs.forksCount_num,
            starCount_num: configs.starCount_num,
            admin_openid_list: configs.admin_openid_list,
            motto: configs.motto,
            userInfo: configs.userInfo,
            hasUserInfo: configs.hasUserInfo,
            service_phoneno: configs.service_phoneno,
            animation: configs.animation,
            cardCur: configs.cardCur,
            swiperList: configs.swiperList,
            expressList: configs.expressList,
            gridCol: configs.gridCol,
            skin: configs.skin,

          })

        }
        console.log(res.data[0])

        console.log(res)
      },
      fail(res) {
        console.log(res)

      },
      complete(res) {
        console.log(res)
        // 关闭加载中！

      }


    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  textareaAInput(res){
    console.log(res)
    this.setData({
      Notice:res.detail.value
    })
  },
  commit(res){
    var that=this
    console.log(res)
    console.log(res.detail.value.Price)

    console.log(res.detail.value.service_phoneno)

    //return
    const db = wx.cloud.database()
    const _ = db.command
    db.collection('configs').doc("b75ec551-eddd-4830-a830-5af35af0c7cb").update({
      data: {
        Price: res.detail.value.Price,
        
        service_phoneno: res.detail.value.service_phoneno,
        Notice: that.data.Notice
      },
      success(res) {
        console.log(res)
        wx.showToast({
          title: '保存成功！',
        })
       // that.onLoad()
      }
    })
  
      
  }
})